package com.lanou.bookstore.category.web.servlet.admin;

import com.lanou.bookstore.category.domain.Category;
import com.lanou.bookstore.category.service.CategoryService;
import com.lanou.bookstore.category.service.CategoryServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/acs")
public class AdminCategoryServlet extends HttpServlet {

    CategoryService cs = new CategoryServiceImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String para = req.getParameter("para");
        String cname = req.getParameter("cname");

        if ("query".equals(para)){
            List<Category> list = cs.queryAll();
            req.setAttribute("adminAcsList", list);
            req.getRequestDispatcher("/adminjsps/admin/category/list.jsp").forward(req, resp);
        }

        if ("add".equals(para)){
            req.getRequestDispatcher("/adminjsps/admin/category/add.jsp").forward(req, resp);
        }
        if ("update".equals(para)){
            req.setAttribute("cname",cname);
            req.getRequestDispatcher("/adminjsps/admin/category/mod.jsp").forward(req, resp);
        }
        if ("delete".equals(para)){
            req.setAttribute("cname",cname);
            req.getRequestDispatcher("/adminjsps/admin/category/del.jsp").forward(req, resp);
        }

        }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        req.setCharacterEncoding("UTF-8");
        doGet(req, resp);
    }
}

